package com.vpclub;

import com.vpclub.bean.Person;
import com.vpclub.config.MainConfigOfPropertyValues;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.stream.Stream;

/**
 * @author : leimingchao
 * @date Date : 2021年06月22日 21:44
 */
public class IOCTest_PropertyValue {

    private AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(MainConfigOfPropertyValues.class);

    @Test
    public void test() {

        printBeans(annotationConfigApplicationContext);
        System.out.println("===============================");
        Person person = (Person) annotationConfigApplicationContext.getBean("person");
        System.out.println(person);
        System.out.println("===============================");
        ConfigurableEnvironment environment = annotationConfigApplicationContext.getEnvironment();
        String property = environment.getProperty("person.nickName");
        System.out.println(property);
        //容器关闭
        annotationConfigApplicationContext.close();
    }


    private void printBeans(ApplicationContext applicationContext) {
        Stream.of(applicationContext.getBeanDefinitionNames()).forEach(System.out::println);
    }
}
